package com.desaysv.wandroid.fragment.main.mvp

import com.desaysv.mvp.BasePresenter
import com.desaysv.svhttp.callback.IRequestCallBack
import com.desaysv.wandroid.entity.AirticEntity
import com.desaysv.wandroid.entity.BannerEntity
import com.desaysv.wandroid.entity.BaseRes
import com.desaysv.svnotice.MessageBlockQueue

/**
 * @author linzi
 * @date 2022-11-16
 */
class MainPresenter : BasePresenter<MainContract.IMainView, MainModel>() {
    fun getBanner(){
        model.getBanner(object:IRequestCallBack<BaseRes<List<BannerEntity>?>>{
            override fun start() {
            }

            override fun error(error: Throwable?) {
                view.showBanner(null)
            }

            override fun complete() {
                MessageBlockQueue.getInstance().notify("banner get success","------------")
            }

            override fun response(
                status: Int,
                headers: MutableMap<String, MutableList<String>>?,
                t: BaseRes<List<BannerEntity>?>?
            ) {
                MessageBlockQueue.getInstance().notify("你好啊")
                view.showBanner(t?.data)
            }

        })
    }
    private fun getPageData(page:Int){
        model.getData(page,object :IRequestCallBack<BaseRes<AirticEntity>>{
            override fun start() {
            }

            override fun error(error: Throwable?) {
                view.refreshData(null)
            }

            override fun complete() {
            }

            override fun response(
                status: Int,
                headers: MutableMap<String, MutableList<String>>?,
                t: BaseRes<AirticEntity>?
            ) {
                view.refreshData(t?.data)
            }

        })
    }
    fun getIndexData(page:Int){
        getPageData(page)
    }

    fun getTopAirtics(){
        model.getTopAirtics(object :IRequestCallBack<BaseRes<List<AirticEntity.DatasBean>>>{
            override fun start() {

            }

            override fun error(error: Throwable?) {
                view.refreshData(null)
            }

            override fun complete() {
            }

            override fun response(
                status: Int,
                headers: MutableMap<String, MutableList<String>>?,
                t: BaseRes<List<AirticEntity.DatasBean>>?
            ) {
                view.refreshTopData(t?.data)
            }

        })
    }
}